package com.ning.activitys.skysound.adpter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ning.activitys.skysound.R;
import com.ning.activitys.skysound.beans.MusicDetailsBeans;
import com.ning.activitys.skysound.datas.MusicDetailsTool;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/11.
 */
public class AllMusicAdapter extends BaseAdapter{

    private Context context;
    private ArrayList<MusicDetailsBeans> musicDetailsData = new ArrayList<>();

    public AllMusicAdapter(Context context, ArrayList<MusicDetailsBeans> musicDetailsData) {
        this.context = context;
        this.musicDetailsData = musicDetailsData;
    }

    @Override
    public int getCount() {
        return musicDetailsData.size();
    }

    @Override
    public Object getItem(int position) {
        return musicDetailsData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_music_details,parent,false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.title.setText(musicDetailsData.get(position).getTitle());
        viewHolder.artist.setText( musicDetailsData.get(position).getArtist());

//        Bitmap albumBitmap = MusicDetailsTool.getArtwork(context,
//                musicDetailsData.get(position).getId(), musicDetailsData.get(position).getAlbumID(),
//                true, true);
//        if (albumBitmap != null) {
//            viewHolder.singImage.setImageBitmap(albumBitmap);
//        }
        return convertView;
    }

    static class ViewHolder{
        private TextView title;
        private TextView artist;
        private ImageView singImage;

        public ViewHolder(View view){
            title = (TextView) view.findViewById(R.id.tv_item_title_music_details);
            artist = (TextView) view.findViewById(R.id.tv_item_artist_music_details);
            singImage = (ImageView) view.findViewById(R.id.iv_singer_image_item);
        }
    }
}
